package cn.bdqn.controller;

import cn.bdqn.dao.MenuMapper;
import cn.bdqn.pojo.Menu;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 刘旻昊
 * @Date: Created in 2020/6/22  19:10
 */
@org.springframework.stereotype.Controller
@RestController
public class MenuController {
    @Resource
    MenuMapper menuMapper;
    @GetMapping("/list4")
    public String list(Model model){
        List<Menu> list= menuMapper.listAll();
        model.addAttribute("list",list);
        return "list4";
    }

    @RequestMapping("/index4")
    public String index(Model model){
        List<Menu> list= menuMapper.listAll();
        model.addAttribute("list",list);
        return "index4";
    }
    @ResponseBody
    @RequestMapping("/delete/{id}4")
    public String del(@PathVariable("id") Integer id){
        Integer i=0;
        i= menuMapper.del(id);
        return i.toString();
    }

    @RequestMapping("/toadd4")
    public String add(){
        return "hello";
    }
    @RequestMapping("/add4")
    public String adds(Menu menu, Model model){
        Integer res= menuMapper.insert(menu);
        if (res>0){
            List<Menu> list= menuMapper.listAll();
            model.addAttribute("list",list);
            return "index4";
        }else{
            return "hello";
        }
    }

    @RequestMapping("/selectByid/{id}4")
    public String seleId(@PathVariable("id") Integer id, Model model){
        Menu list= menuMapper.listAllByid(id);
        model.addAttribute("list1",list);
        return "upd";
    }

    @RequestMapping("/upduser4")
    public String upd(Menu menu, Model model){
        Integer res= menuMapper.upd(menu);
        if (res>0){
            List<Menu> list= menuMapper.listAll();
            model.addAttribute("list",list);
            return "index4";
        }else{
            return "upd";
        }
    }
}
